import { State } from './AnimationState'

export class StateMachine<StateEnum> {
  //当前状态
  _state: StateEnum
  //状态机
  _stateMap: Map<StateEnum, State> = new Map()
  //人物当前状态值
  _stateValue: State = null
  //设置状态
  set stateName(stateName: StateEnum) {
    this._state = stateName
    this._stateValue = this._stateMap.get(stateName)
    this.onStateChange()
    this._stateValue.run()
  }
  //获取状态
  get stateName() {
    return this._state
  }
  //获取状态值
  get stateValue() {
    return this._stateValue
  }

  //添加状态
  addState(stateName: StateEnum, state: State) {
    this._stateMap.set(stateName, state)
  }

  //状态改变时
  onStateChange() {}
}
